package com.frame.work.frame.deal.util;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.frame.work.config.SpringUtil;
import com.frame.work.entity.DeviceAssociatedInformation;
import com.frame.work.entity.TblDeviceActions;
import com.frame.work.mapper.SelectDeviceMapper;
import org.apache.commons.lang3.StringUtils;

import java.util.LinkedList;
import java.util.List;


/**
 * @author wjming
 * @ClassName: DeviceAssociatedInformationUtil
 * @Description:设备关联信息工具类
 * @Date 2021/1/27 11:25
 */
public class DeviceRelationMessageUtil {
    public static List<DeviceAssociatedInformation> getDeviceUserMessage(String deviceMac) {
        SelectDeviceMapper testMapper = SpringUtil.getBean(SelectDeviceMapper.class);
        List<DeviceAssociatedInformation> list = testMapper.getDevice1(deviceMac);
        return list;
    }

    /**
     * @Description:用于获取Action中对应参数的对应值
     * @param: deviceMac
     * @param: od
     * @param: deviceType
     * @param: productType
     * @param: params，找到action中对应的key并取出其值
     * @return: java.util.List<String>
     * @author:wjming
     * @Date:2021/1/27 13:09
     */
    public static List<String> getDeviceActionParamsValue(String deviceMac, String od,
                                                          String deviceType, String productType, List<String> params) {
        List<String> linkedList = new LinkedList<>();
        List<TblDeviceActions> deviceActions = getDeviceActionMessage(deviceMac, od, deviceType, productType);
        if (CollectionUtils.isEmpty(deviceActions)) {
            return null;
        }
        for (String param : params) {
            deviceActions.forEach(list -> {
                if (StringUtils.equals(param, list.getActionsKey())) {
                    linkedList.add(list.getActionsValue());
                }
            });
        }

        return linkedList;
    }

    /**
     * @Description:用于获取Action信息
     * @param: deviceMac
     * @param: od
     * @param: deviceType
     * @param: productType
     * @return: java.util.List<com.frame.work.entity.TblDeviceActions>
     * @author:wjming
     * @Date:2021/1/27 13:36
     */
    public static List<TblDeviceActions> getDeviceActionMessage(String deviceMac, String od,
                                                                String deviceType, String productType) {

        SelectDeviceMapper testMapper = SpringUtil.getBean(SelectDeviceMapper.class);
        List<TblDeviceActions> deviceActions = testMapper.getDevice2(deviceMac, od, deviceType, productType);
        return deviceActions;
    }






}
